package com.yisu.auction.manager.core.service.impl;

import com.yisu.auction.ewf.common.web.EasyUIGrid;
import com.yisu.auction.ewf.entity.GoodsInfo;
import com.yisu.auction.ewf.entity.SecKillActivity;
import com.yisu.auction.manager.core.mapper.GoodsInfoMapper;
import com.yisu.auction.manager.core.mapper.SecKillActivityMapper;
import com.yisu.auction.manager.core.service.ISecKillActivityService;
import com.yisu.auction.manager.domain.request.baseInfoPackage.SecKillActivityRequest;
import com.yisu.auction.manager.domain.vo.baseInfoPackageVos.GoodsExpandInfoVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * author: 赵杰
 * Business Description：秒差活动接口业务实现
 * createTime：2017/8/23
 */
@Service
public class SecKillActivityServiceImpl extends BaseService implements ISecKillActivityService {
    @Resource
    private SecKillActivityMapper secKillActivityMapper;
    @Resource
    private GoodsInfoMapper goodsInfoMapper;

    /**
     * author:赵杰
     * Business Description : 分页获取秒差活动商品信息
     *
     * @param secKillActivityRequest 分页请求信息
     * @return 商品分类列表
     */
    @Override
    public EasyUIGrid<SecKillActivity> getSecKillActivityByPage(SecKillActivityRequest secKillActivityRequest) {
        List<SecKillActivity> secKillActivities = secKillActivityMapper.getSecKillActivityByPage(secKillActivityRequest);
        EasyUIGrid<SecKillActivity> gridData = new EasyUIGrid<>();
        gridData.setTotal(secKillActivityRequest.getTotalRecords());
        gridData.setRows(secKillActivities);
        return gridData;
    }

    /**
     * author:赵杰
     * Business Description : 分页获取秒差活动商品信息
     *
     * @param secKillActivityRequest goodsId
     * @return
     */
    @Override
    public boolean joinSecKillByGoodsId(SecKillActivityRequest secKillActivityRequest) {
        GoodsInfo goodsInfo = goodsInfoMapper.selectByPrimaryKey(secKillActivityRequest.getGoodsId());
        if (goodsInfo == null)
            return false;
        SecKillActivity insertModel = new SecKillActivity();
        insertModel.setName(goodsInfo.getName());
        insertModel.setTerm(1);
        insertModel.setImage(goodsInfo.getImages());
        insertModel.setGoodsDetail(goodsInfo.getDetail());
        insertModel.setGoodsTypeId(goodsInfo.getGoodsTypeId());
        insertModel.setGoodsId(goodsInfo.getId());
        return secKillActivityMapper.insertSelective(insertModel)>0;
    }

    /**
     * author:赵杰
     * Business Description : 通过主键ID获取秒杀信息
     * @param secKillActivityRequest
     * @return
     */
    @Override
    public SecKillActivity getSecKillActivityById(SecKillActivityRequest secKillActivityRequest) {
        return secKillActivityMapper.selectByPrimaryKey(secKillActivityRequest.getId());
    }

    /**
     * author:赵杰
     * Business Description : 修改秒杀信息
     * @param secKillActivity
     * @return
     */
    @Override
    public boolean updateSecKillActivity(SecKillActivity secKillActivity) {
        return secKillActivityMapper.updateByPrimaryKeySelective(secKillActivity)>0;
    }

}
